using System;
using System.Data;
//using System.Collections;
using System.Collections.Generic;
using System.Text;
using Entity;

namespace Bussiness
{
    public static class ManageSetting
    {
        public static bool Add(Setting record)
        {
            object[] param = { record.name, record.memo, record.type, record.Id };

            try
            {
                DataAccess.DB().ExecuteScalar("usp_InsertT_Setting", param);
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }

        public static List<Setting> GetDefineByType(CDefine type)
        {
            List<Setting> result = new List<Setting>();
            using (IDataReader reader = DataAccess.DB().ExecuteReader("usp_SelectT_SettingByType", type))
            {
                while (reader.Read())
                {
                    Setting tmp = new Setting(reader[0],reader[1],reader[2]);
                    result.Add(tmp);
                    
                }
            }

            return result;
        }

        public static List<City> GetSubCities(int parentid)
        {
            List<City> result = new List<City>();
            using (IDataReader reader = DataAccess.DB().ExecuteReader("usp_SelectT_City", parentid))
            {
                while (reader.Read())
                {
                    City tmp = new City(reader[0], reader[1]);
                    result.Add(tmp);

                }
            }

            return result;
        }

        public static List<City> GetCities()
        {
            List<City> result = new List<City>();
            using (IDataReader reader = DataAccess.DB().ExecuteReader(CommandType.Text, "usp_SelectT_CitiesAll"))
            {
                while (reader.Read())
                {
                    City tmp = new City(reader[0], reader[1]);
                    result.Add(tmp);

                }
            }

            return result;
        }

        
    }
}
